<?php

/**
 * MVM_MALL 网上商店系统  系统整合管理
 * ============================================================================
 * 版权所有 (C) 2007-2010 www.mvmmall.com，并保留所有权利。
 * 网站地址: http://www.mvmmall.com
 * ----------------------------------------------------------------------------
 * 这是一个免费开源的软件；这意味着您可以在不用于商业目的的前提下对程序代码
 * 进行修改、使用和再发布。
 * ============================================================================
 * $Author:  www.mvmmall.com  $
 * $Date: 2008-07-14 $
 * $Id: passport.inc.php www.mvmmall.com$
 * ---------------------------------------------
*/

if(!defined('MVMMALL') || !defined('IN_ADMINCP')) exit('Access Denied');
if ($action=='list') {
    $port_rt = get_dirinfo(MVMMALL_ROOT.'./include/passport');
    for ($i = 0; $i < count($port_rt); $i++) {
        require MVMMALL_ROOT.'./include/passport/'.$port_rt[$i];
        $name = dhtmlchars(str_replace('.class.php','',$port_rt[$i]));
        $port = $db->get_one("SELECT id,class_name FROM `{$tablepre}passport` WHERE class_name='$name'");
        if($port['class_name']){
            $passport[$port['class_name']]['install'] = 1;
            $passport[$port['class_name']]['id']      = $port['id'];
            $passport[$port['class_name']]['edit']    = "admincp.php?module=$module&action=edit&uid=$port[id]";
            $passport[$port['class_name']]['del']     = "admincp.php?module=$module&action=del&uid=$port[id]";
        }
        $passport[$name]['insert']                    = "admincp.php?module=$module&action=add&name=$name";
    }
    require template('passport');
    footer();
} elseif ($action=='add' && isset($name)) {
    if($setp==1 && $_POST){
        $port_rt = $db->get_one("SELECT id,class_name FROM `{$tablepre}passport` WHERE class_name='$name'");
        if($port_rt['class_name']){
            admin_msg('plug_exist');
        } else {
            if(!file_exists(MVMMALL_ROOT.'./include/passport/'.$name.'.class.php')){
                admin_msg('plug_noexist');
            } else {
                require_once  MVMMALL_ROOT.'./include/passport/'.$name.'.class.php';
            }
            $config = array();
            foreach ($passport[$name]['cfg'] AS $key => $val)
            {
                $config[$key]['name']   = $val['name'];
                $config[$key]['value']  = $$val['name'];
                $config[$key]['label']  = $val['label'];
            }
            $config = serialize($config);
            $query = "INSERT INTO `{$tablepre}passport`  SET
                  class_name       = '$name',
                  name             = '$passport_name',
                  passport_desc    = '$passport_desc',
                  online           = '$payment[$name][online]',
                  cfg              = '$config'
                 ";
            $db->query($query);
        }
        admin_msg('success','admincp.php?module=passport&action=list');
    } else {
        $name   = dhtmlchars($name);
        if(!file_exists(MVMMALL_ROOT.'./include/passport/'.$name.'.class.php')){
            admin_msg('plug_noexist');
        } else {
            require_once  MVMMALL_ROOT.'./include/passport/'.$name.'.class.php';
        }
        $fields = array();
        foreach ($passport[$name]['cfg'] AS $key => $val)
        {
            $fields[$key]['name']   = $val['name'];
            $fields[$key]['value']  = $val['value'];
            $fields[$key]['label']  = $val['label'];
        }
        @extract($passport[$name],EXTR_OVERWRITE);
        include template('passport_add');
        footer();
    }
} elseif ($action=='edit' && is_numeric($uid)) {
    if($setp==1 && $_POST){
        $pay           = $db->get_one("SELECT id,class_name FROM {$tablepre}passport WHERE id='$uid'");
        $name          = $pay['class_name'];
        $passport_name = dhtmlchars($passport_name);
        $nums          = $db->counter("{$tablepre}passport","where  name='$passport_name' AND id <> '$uid'");
        if($nums>0){
            admin_msg('plug_exist');
        } else {
            if(!file_exists(MVMMALL_ROOT.'./include/passport/'.$name.'.class.php')){
                admin_msg('plug_noexist');
            } else {
                require_once  MVMMALL_ROOT.'./include/passport/'.$name.'.class.php';
            }
            $config = array();
            foreach ($passport[$name]['cfg'] AS $key => $val)
            {
                $config[$key]['name']   = $val['name'];
                $config[$key]['value']  = $$val['name'];
                $config[$key]['label']  = $val['label'];
            }
            $config = serialize($config);
            $query = "UPDATE `{$tablepre}passport` SET
                  class_name      = '$name',
                  name            =  '$passport_name',
                  passport_desc   =  '$passport_desc',
                  online          = '$passport[$name][online]',
                  cfg             = '$config'
                  WHERE id = '$uid' ";
            $db->query($query);
        }
        admin_msg('success','admincp.php?module=passport&action=list');
    } else {
        $port         = $db->get_one("SELECT * FROM `{$tablepre}passport` WHERE id='$uid'");
        $port ['cfg'] = unserialize($port['cfg']);
        $fields = array();
        foreach ($port['cfg'] AS $key => $val)
        {
            $fields[$key]['name']   = $val['name'];
            $fields[$key]['value']  = $val['value'];
            $fields[$key]['label']  = $val['label'];
        }
        @extract($port,EXTR_OVERWRITE);
        $desc   = $passport_desc;
        require template('passport_add');
    }
} elseif ($action=='del' && is_numeric($uid)){
    $db->query("DELETE FROM `{$tablepre}passport` WHERE id='$uid'");
    admin_msg('success','admincp.php?module=passport&action=list');
} else {
    admin_msg('pass_worng');
}